package aos.client.gui;

import java.awt.AWTEvent;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;

import org.apache.log4j.Logger;
import thinlet.Pane;
import thinlet.RootPane;
import thinlet.Widget;
import thinlet.event.Listener;
import thinlet.layout.InlineLayout;
import thinlet.layout.Layout;
import thinlet.layout.Metrics;
import thinlet.layout.RowLayout;

public class HeadController extends Widget {
	
	static Logger logger = Logger.getLogger(HeadController.class);
	
	float x = 0.5f;
	float y = 0.3f;
	
	public HeadController() {
		setBounds(0, 0, 100, 100);
	}
	
	protected boolean isFocusable() {
		return false;
	}
	
	public float getValueX() {
		return this.x;
	}
	
	public float getValueY() {
		return this.y;
	}
	
	public void left() {
		setValues(this.x - 0.01f, this.y);	
	}
	
	public void right() {
		setValues(this.x + 0.01f, this.y);
	}
	
	public void up() {
		setValues(this.x, this.y - 0.01f);
	}
	
	public void down() {
		setValues(this.x, this.y + 0.01f);	
	}
	
	public void center() {
		setValues(0.5f, 0.3f);
	}
	
	public void setValues(float x, float y) {
		x = Math.max(0, Math.min(x, 1));
		y = Math.max(0, Math.min(y, 1));
		
		if ((this.x != x) || (this.y != y)) {
			this.x = x;
			this.y = y;
			repaint();
		}
	}
	
	
	protected void paint(java.awt.Graphics2D g) {
		g.setColor(java.awt.Color.orange);
		g.fillRect((int)(this.x * (94)), (int)(this.y * (94)), 6, 6);
		g.setColor(java.awt.Color.gray);
		g.drawRect((int)(this.x * (94)), (int)(this.y * (94)), 6, 6);
		
		g.drawLine(0, 15, 100, 15);
		g.drawLine(0, 45, 100, 45);
		g.drawLine(35, 0, 35, 100);
		g.drawLine(65, 0, 65, 100);
		g.drawRect(0, 0, 100, 100);
		
		
	}
	
	protected Widget getWidgetAt(int mx, int my) {
		return null;
	}
	
	public Metrics getPreferredSize(int preferredWidth) {
		return new Metrics(101, 101);
	}

	public static void main(String[] args) {
		HeadController headController = new HeadController();
		headController.setBounds(0, 0, 100, 100);
		JFrame frame = new RootPane(headController).showFrame(101, 101);
		frame.setTitle("AoS - Arduino over Skype");
		
		logger.info("Client initialized.");
	}
	
	
}
